Improve volume matching on macOS and fix snapshot-based volume handling on macOS - #21
Merged
Conversation
wknapik
marked this pull request as ready for review
August 15, 2026 04:28
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR updates the macOS (Darwin) volume-to-disk resolution and formatting/mounting flow to avoid relying on the EBS volume ID as a disk label, and updates documentation/sudoers guidance accordingly.
Changes:
- Resolve macOS disks via
system_profilerNVMe inventory and APFS container mapping. - Generate a random volume name for
diskutil eraseDiskon macOS and adjust mounting to use device paths. - Update README disclaimer and tighten/adjust sudoers command aliases for the new behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| vol | Reworks macOS disk discovery and changes format/mount behavior to use device nodes and random volume names. |
| README.md | Updates disclaimer text and adapts sudoers regexes to the new diskutil invocation patterns. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
wknapik
enabled auto-merge (squash)
August 15, 2026 12:45
mihaiplesa
approved these changes
Aug 17, 2026
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
Suppressed comments (2)
vol:297
- Indexing with
[0]on the filtered list will raiseIndexErrorif no APFS container matches the NVMe physical store (or if expected keys/arrays are missing). Prefer locating a single match withnext(..., None)and emitting a clearerr(...)when not found so failures surface as actionable errors instead of an unhandled exception.
containers = run2json(['diskutil', 'apfs', 'list', '-plist'])['Containers']
device = [c['Volumes'][0]['DeviceIdentifier'] for c in containers
if c['PhysicalStores'][0]['DeviceIdentifier'] == nvme_matching['volumes'][0]['bsd_name']][0]
vol:285
system_profileris typically slow, andget_disk()appears to be called in mount/format flows (and likely in polling loops such aswait_for_disk). Consider caching the parsed NVMe inventory for the duration of a mount operation (or for a short TTL) to avoid repeated expensive subprocess calls.
nvme_all = json.loads(run(['system_profiler', '-json', 'SPNVMeDataType']).stdout)['SPNVMeDataType']
nvme_items = sum((i['_items'] for i in nvme_all if i['_items']), [])
nvme_matching = next((i for i in nvme_items if i['device_serial'] == volume_id.replace('-', '')), None)
| if c['PhysicalStores'][0]['DeviceIdentifier'] == nvme_matching['volumes'][0]['bsd_name']][0] | ||
| return f'/dev/{device}' | ||
| else: | ||
| return f'/dev/{nvme_matching['bsd_name']}' |
| ```bash | ||
| sudo install -Tm440 /dev/stdin /etc/sudoers.d/99-vol <<-'EOF' | ||
| Cmnd_Alias VOL_FORMAT = /usr/sbin/diskutil ^eraseDisk -noEFI APFS vol-[0-9a-fA-F]+ /dev/disk[1-9][0-9]*$ | ||
| Cmnd_Alias VOL_FORMAT = /usr/sbin/diskutil ^eraseDisk -noEFI APFS [a-zA-Z]+ /dev/disk[1-9][0-9]*$ |
Comment on lines
+305
to
+307
| Cmnd_Alias VOL_FORMAT = /usr/sbin/diskutil ^eraseDisk -noEFI APFS [a-zA-Z]+ /dev/disk[1-9][0-9]*$ | ||
| Cmnd_Alias VOL_MOUNT = /usr/sbin/diskutil ^mount -mountPoint /mnt/point /dev/disk[1-9][0-9]*$ | ||
| Cmnd_Alias VOL_UMOUNT = /usr/sbin/diskutil ^umount /mnt/point$, /usr/sbin/diskutil ^umount /Volumes/[a-zA-Z]+$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Snapshot-based volumes retain the origin volume name, so that's not a reliable way to match the AWS-level device to the macOS-level device.
Found a more reliable way to make the connection.
This PR also fixes handling of snapshot-based volumes on macOS.